<template>
  <div style="height: 100%; width: 100%; position: relative;" ref="maindev">
    <div class="pagetop">
      <div style="width:100%">
        <table style="width: 100%; font-size: 12px;white-space: nowrap;" border="0">
          <col style="width: 6%;" />
          <col style="width: 11%;" />
          <col style="width: 1%;" />
          <col style="width: 11%;" />
          <col style="width: 6%;" />
          <col style="width: 11%;" />
          <col style="width: 5%;" />
          <col style="width: 12%;" />
          <col style="width: 6%;" />
          <col style="width: 13%;" />
          <col style="width: 7%;" />
          <col style="width: 11%;" />
          <tr>
            <td align="right">
              日期
            </td>
            <td>
              <el-date-picker v-model="searchobj.strdate" :clearable="false" type="date" placeholder="选择日期"
                value-format="yyyy-MM-dd" style="width: 100%;"> </el-date-picker>
            </td>
            <td>至</td>
            <td>
              <el-date-picker v-model="searchobj.enddate" type="date" :clearable="false" placeholder="选择日期"
                value-format="yyyy-MM-dd" style="width: 100%;"> </el-date-picker>
            </td>
            <td align="right">标本类型</td>
            <td>
              <el-select v-model="searchobj.sample"
                @dblclick.native="popMultipleChk(searchobj.sample, 'sample', specimenOption, '请选择标本类型')" filterable
                clearable>
                <el-option v-for="(item, index) in specimenOption" :key="index" :value="item.data"
                  :label="item.display"></el-option>
              </el-select>
            </td>
            <td align="right">科室</td>
            <td>
              <el-select v-model="searchobj.reqdept"
                @dblclick.native="popMultipleChk(searchobj.reqdept, 'reqdept', deptOption, '申请科室选择')" filterable
                clearable>
                <el-option v-for="(item, index) in deptOption" :key="index" :value="item.data" :label="item.display">
                </el-option>
              </el-select>
            </td>
            <td align="right">性&nbsp;&nbsp;&nbsp;别</td>
            <td>
              <table style="border-spacing:0px">
                <tr>
                  <td>
                    <el-select v-model="searchobj.patsex" style="width: 100%;" clearable>
                      <el-option v-for="(item, index) in sexOption" :key="index" :label="item.label"
                        :value="item.value"></el-option>
                    </el-select>
                  </td>
                  <td>&nbsp;</td>
                  <td>

                    <el-checkbox true-label="1" false-label="0" v-model="searchobj.bypat">
                      <span style="font-size:12px">按病人统计</span>
                    </el-checkbox>
                  </td>
                </tr>
              </table>
            </td>
            <td align="right">耐药机制</td>
            <td>
              <el-select v-model="searchobj.rescode" clearable filterable style="width:100%">
                <el-option v-for="(item, index) in resdictOption" :key="index" :label="item.display" :value="item.data">
                  <span style="float: left">{{ item.display }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.data }}</span>
                </el-option>
              </el-select>
            </td>
          </tr>
          <tr>
            <td align="right">报告单元</td>
            <td colspan="3">
              <el-select v-model="searchobj.rptunitid"
                @dblclick.native="popMultipleChk(searchobj.rptunitid, 'rptunitid', rptunitOption, '请选择报告单元')" filterable
                clearable style="width:100%">
                <el-option v-for="(item, index) in rptunitOption" :key="index" :value="item.data"
                  :label="item.display"></el-option>
              </el-select>
            </td>
            <td align="right">病人类型</td>
            <td>
              <!-- @dblclick.native="popMultipleChk(txtpattype, 'txtpattype', pattypeOption, '病人类型选择')" -->
              <el-select v-model="searchobj.pattype" filterable clearable>
                <el-option v-for="(item, index) in pattypeOption" :value="item.data" :label="item.display"
                  :key="index"></el-option>
              </el-select>
            </td>
            <td align="right">病区</td>
            <td>
              <el-select v-model="searchobj.reqward"
                @dblclick.native="popMultipleChk(searchobj.reqward, 'reqward', wardOption, '病区选择')" filterable clearable>
                <el-option v-for="(item, index) in wardOption" :key="index" :value="item.data" :label="item.display">
                </el-option>
              </el-select>
            </td>
            <td align="right">细菌组</td>
            <td>
              <el-select v-model="searchobj.germcomb"
                @dblclick.native="popMultipleChk(searchobj.germcomb, 'germcomb', germcombOption, '细菌组')" filterable
                clearable>
                <el-option v-for="(item, index) in germcombOption" :key="index" :value="item.data" :label="item.display">
                </el-option>
              </el-select>
            </td>
            <td align="right">送检医院</td>
            <td colspan="3">
              <rm-ddl-common @change="hospitalchange" datatype="hospital" dataname="送检医院" v-model="searchobj.hospitalcode"
                width="100%" :clearable="true"></rm-ddl-common>
            </td>
          </tr>
        </table>
        <div class="operation-list">
          <el-button @click.native="BtnQuery" type="primary" icon="el-icon-search">查询</el-button>
          <el-button @click.native="BtnStatistics" icon="el-icon-edit-outline">统计</el-button>
          <el-button @click.native="BtnClear" icon="el-icon-close">清除</el-button>
          <!-- <el-button @click.native="BtnPrint" icon="el-icon-printer">打印</el-button> -->
          <el-button @click.native="BtnExport" icon="el-icon-download">导出</el-button>
          <el-button @click.native="BtnNextOne" icon="el-icon-thumb">下一个</el-button>
          <!-- <el-button @click.native="BtnReplaeFrequency" icon="el-icon-refresh">更换频次</el-button> -->
        </div>
      </div>
    </div>
    <div class="pagecenter">
      <div class="middle-center">
        <rm-layout-left splitcolor="white" movingcolor="#0000ff" :splitwidth=5 :fixsize=360>
          <template v-slot:fix>
            <div style="height:100%">
              <vxe-table :data.sync="leftTableData" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }"
                border height="auto" highlight-current-row class="mytable-style" highlight-hover-column
                highlight-hover-row how-header-overflow ref="xTable" resizable show-overflow size="mini" stripe
                show-header-overflow :optimization="{ animat: false }" header-align="center" :loading="leftloading">
                <vxe-table-column field="chkflag" sortable title="选择" width="40" align="center">
                  <template v-slot="{ row }">
                    <el-checkbox v-model="row.chkflag" @change="ChkflagChange(row)" true-label="1"
                      false-label="0"></el-checkbox>
                  </template>
                </vxe-table-column>
                <vxe-table-column field="rpt_itemname" sortable title="细菌名称" width="150">
                </vxe-table-column>
                <vxe-table-column field="cp_germcnt" sortable title="标本数" width="60" align="center">
                </vxe-table-column>
                <vxe-table-column field="cp_patcnt" sortable title="人数" width="50" align="center">
                </vxe-table-column>
                <vxe-table-column field="chkcnt" sortable title="序号" width="50" align="center">
                </vxe-table-column>
              </vxe-table>
            </div>
          </template>

          <div style="height:100%;width:100%;" class="myclass">
            <vxe-table border :data.sync="rightTableData" header-align="center" height="auto" highlight-current-row
              highlight-hover-column highlight-hover-row ref="Main_Table" resizable show-overflow size="mini" stripe
              show-header-overflow :optimization="{ animat: false }" :key="xTablekey" :loading="rightloading"
              @cell-dblclick="rCellDblClick" :cell-class-name="cellClassName">
              <vxe-table-column field="medname" title="抗生素" width="110"></vxe-table-column>
              <vxe-table-column :title="sitems.title" v-for="(sitems, index) in columnData" :key="index" width="200"
                show-header-overflow="ellipsis">
                <vxe-table-column :field="m.field" :title="m.title" v-for="(m, mindex) in sitems.content" :key="mindex"
                  width="82" align="center">
                </vxe-table-column>
              </vxe-table-column>
            </vxe-table>
          </div>
        </rm-layout-left>
      </div>
    </div>

    <!--多选弹窗--->
    <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="multichktitle"
      :visible.sync="dialogMultipleVisible" :destroy-on-close="true">
      <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname" @change="closedialog">
      </rm-SqlMultiple>
    </el-dialog>
    <!--导出弹窗-->
    <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="导出"
      :visible.sync="dialogExport" width="840px">
      <div style="margin:20px">选择左边表格则导出左边表格中的结果信息，选择右边表格则导出右边表格中的结果明细信息，选择取消则取消本次导出！</div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="exportfun(1)">左边表格</el-button>
        <el-button type="primary" @click="exportfun(2)">右边表格</el-button>
        <el-button @click="dialogExport = false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 明细查看 -->
    <el-dialog width="80%" title="明细查看" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false"
      :visible.sync="dialogDetailVisible" :destroy-on-close="true">
      <div style="height: 75px; width: 100%">
        <h3 style="text-align: center; width: 100%">
          <span>抗生素”{{ antibiotic }}“针对细菌”{{ bacteria }}“的反应为”{{ reaction }}“的病人明细</span>
        </h3>
        <span>日期：{{ searchobj.strdate }}至{{ formateDateTime(searchobj.enddate) }}</span>
        <table style="width: 100%; font-size: 12px;white-space: nowrap;" border="0">
          <tr>
            <td>
              <el-button @click.native="BtnExportDetail" icon="el-icon-download">导出</el-button>
            </td>
          </tr>
        </table>
      </div>
      <div style="height: 700px; width: 100%">
        <vxe-table ref="patdetailtable" :data.sync="patdetailtabledata" :select-config="{ reserve: true }"
          :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column
          highlight-hover-row how-header-overflow resizable show-overflow size="mini" show-header-overflow
          :optimization="{ animat: false }" header-align="center">
          <vxe-table-column field="barcode" title="条码号" width="100" header-align="center" align="center" sortable>
          </vxe-table-column>
          <vxe-table-column field="hospcode" title="送检医院" width="200" header-align="center" align="left"
            :formatter="formatFun" sortable>
          </vxe-table-column>
          <vxe-table-column field="sampleno" title="标本编号" width="120" header-align="center" align="center" sortable>
          </vxe-table-column>
          <vxe-table-column field="specimen_code" title="标本类型" width="110" header-align="center" align="center"
            :formatter="formatFun" sortable></vxe-table-column>
          <vxe-table-column field="recieve_dt" title="接收时间" width="120" header-align="center" align="center"
            sortable></vxe-table-column>
          <vxe-table-column field="pat_no" title="病人号" width="90" header-align="center" align="center" sortable>
          </vxe-table-column>
          <vxe-table-column field="pat_name" title="病人姓名" width="80" header-align="center" align="center" sortable>
          </vxe-table-column>
          <vxe-table-column field="pat_ageyear" title="年龄" width="60" header-align="center" align="center" sortable>
          </vxe-table-column>
          <vxe-table-column field="pat_typecode" title="来源" width="70" header-align="center" align="center"
            :formatter="formatFun" sortable>
          </vxe-table-column>
          <vxe-table-column field="req_deptno" title="申请科室" width="130" header-align="center" align="center"
            :formatter="formatFun" sortable>
          </vxe-table-column>
          <vxe-table-column field="req_wardno" title="病区" width="120" header-align="center" align="center"
            :formatter="formatFun" sortable>
          </vxe-table-column>
          <vxe-table-column field="req_bedno" title="床号" width="60" header-align="center" align="center" sortable>
          </vxe-table-column>
          <vxe-table-column field="req_docno" title="申请医生" width="80" header-align="center" align="center" sortable>
          </vxe-table-column>
          <vxe-table-column field="pat_diag" title="临床诊断" width="200" header-align="center" align="left" sortable>
          </vxe-table-column>
        </vxe-table>
      </div>
    </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  name: "LIS943",
  data() {
    return {
      sexOption: [
        { label: "", value: "" },
        { label: "男", value: "1" },
        { label: "女", value: "2" },
        { label: "未知", value: "3" },
      ],
      dialogMultipleVisible: false,
      leftloading: false,
      rightloading: false,
      dialogExport: false,
      dialogDetailVisible: false,
      option1: [],
      option2: [],
      fieldname: "",
      tableColumn: [],
      tableData: [],
      xTablekey: 0,
      multichktitle: "",
      pattypeOption: [],
      deptOption: [],
      wardOption: [],
      hospOption: [],
      doctorOption: [],
      rptunitOption: [],
      rptunitGroupOption: [],
      reportcommOption: [],
      labgroupOption: [],
      specimenOption: [],
      deptgroupOption: [], //deptcomb
      resdictOption: [],
      germcombOption: [],
      rightTableData: [],
      leftTableData: [],
      patdetailtabledata: [],
      //以下为查询条件
      searchobj: {
        strdate: this.$pub.InitDateTime2(0).datefrom,
        enddate: this.$pub.InitDateTime2(0).dateto,
        sample: "",
        pattype: "",
        patsex: "",
        deptgroup: "",
        rptunitid: "",
        hospitalcode: "",
        reqdept: "",
        reqward: "",
        germcomb: "",
        rescode: "",
        bypat: 0,
      },
      antibiotic: "",
      bacteria: "",
      reaction: "",
      //以下为右表列名
      columnData: [],
      exportTableColLen: 0,
      hospitalname: "",
    };
  },
  created() {
    this.initColumn();
    this.initOption();
  },
  mounted() { },
  updated() { },
  methods: {
    popMultipleChk(e, fieldname, option, title) {
      let temp = XEUtils.clone(option, true);
      this.option1 = [];
      this.option2 = [];
      if (e != "") {
        let k = e.split(",");
        k.forEach((item) => {
          let ndata = temp.find((m) => m.data == item);
          if (ndata != undefined && ndata != null) {
            this.option2.push(ndata);
          }
        });
        temp.forEach((item) => {
          if (k.indexOf(item.data + "") < 0) {
            this.option1.push(item);
          }
        });
      } else {
        this.option1 = temp;
      }
      this.fieldname = fieldname;
      this.multichktitle = title;
      this.dialogMultipleVisible = true;
    },
    closedialog(value, name) {
      if (value != "close") {
        this.searchobj[name] = value;
      }
      this.dialogMultipleVisible = false;
    },
    formateDateTime(value) {
      return XEUtils.toDateString(value, "yyyy-MM-dd");
    },
    initColumn() {
      this.columnData = new createColumn();
      function createColumn() {
        let data = [];
        for (let index = 0; index < 10; index++) {
          const title = "细菌" + (index + 1);
          const content = [
            { field: "R%", title: "R%" },
            { field: "I%", title: "I%" },
            { field: "S%", title: "S%" },
          ];
          data.push({ title: title, content: content });
        }
        data.push({
          title: "平均",
          content: [
            { field: "R%", title: "R%" },
            { field: "I%", title: "I%" },
            { field: "S%", title: "S%" },
          ],
        });
        return data;
      }
    },
    async initOption() {
      try {
        const res = await this.$tool.request({
          url: "LIS/LIS6/LIS610",
          method: "post",
          data: {
            action: "initOption",
          },
        });
        this.pattypeOption = res.pattypeOption;
        this.deptOption = res.deptOption;
        this.hospOption = res.hospOption;
        this.rptunitOption = res.rptunitOption;
        this.wardOption = res.wardOption;
        this.specimenOption = res.specimenOption;
        this.germcombOption = res.germcombOption;
        this.resdictOption = res.rescodeOption;
      } catch (e) {
        this.$message.warning(e);
      }
    },
    BtnQuery() {
      this.InitPage();
    },
    BtnClear() {
      this.searchobj = {
        strdate: this.$pub.InitDateTime2(0).datefrom,
        enddate: this.$pub.InitDateTime2(0).dateto,
        sample: "",
        pattype: "",
        patsex: "",
        deptgroup: "",
        rptunitid: "",
        hospitalcode: "",
        reqdept: "",
        reqward: "",
        germcomb: "",
        rescode: "",
        bypat: 0,
      };
      this.leftTableData = [];
      this.rightTableData = [];
    },
    BtnExport() {
      this.dialogExport = true;
    },
    BtnExportDetail() {
      let data = this.getExportData();
      let filtertxt = "抗生素“" + this.antibiotic + "”针对细菌“" + this.bacteria + "”的反应为“" + this.reaction + "”的病人明细; "
      this.$pub.exportTableExcelWithData(data, this.exportTableColLen, "LIS943 常见10种细菌耐药统计表病人明细.xlsx", filtertxt, "查询条件：");
    },
    getExportData() {
      let datas = this.$refs.patdetailtable.afterFullData;
      let exportColumn = XEUtils.clone(this.tableColumn, true);

      exportColumn.push({ field: "barcode", title: "条码号" });
      exportColumn.push({ field: "hospcode", title: "送检医院" });
      exportColumn.push({ field: "sampleno", title: "标本编号" });
      exportColumn.push({ field: "specimen_code", title: "标本类型" });
      exportColumn.push({ field: "recieve_dt", title: "接收时间" });
      exportColumn.push({ field: "pat_no", title: "病人号" });
      exportColumn.push({ field: "pat_name", title: "病人姓名" });
      exportColumn.push({ field: "pat_ageyear", title: "年龄" });
      exportColumn.push({ field: "pat_typecode", title: "来源" });
      exportColumn.push({ field: "req_deptno", title: "申请科室" });
      exportColumn.push({ field: "req_wardno", title: "病区" });
      exportColumn.push({ field: "req_bedno", title: "床号" });
      exportColumn.push({ field: "req_docno", title: "申请医生" });
      exportColumn.push({ field: "pat_diag", title: "临床诊断" });
      this.exportTableColLen = exportColumn.length;
      let columns = exportColumn.filter((item) => item.field);
      let footerData = {};

      datas.splice(datas.length, 0, footerData);
      let headers = [columns.map((item) => item.title)];
      return headers.concat(
        datas.map((row) => {
          return columns.map((column) => {
            return this.retForamtVal(row[column.field], column.field);
          });
        })
      );
    },
    exportfun(index) {
      if (index == "1") {
        this.tableColumn = [];
        let tableColumn = this.$refs.xTable.getColumns();
        tableColumn.forEach((item) => {
          this.tableColumn.push({ title: item.title, field: item.property });
        });
        let filtertxt = this.getExportFilter();
        this.$pub.exportTableExcel(this.leftTableData, this.tableColumn, "LIS943 常见10种细菌耐药统计表result.xlsx", filtertxt, "统计条件：");
      } else {
        // let options = {
        //     filename: "LIS943 常见10种细菌耐药统计表detail.csv",
        // };
        // this.$refs.Main_Table.exportCsv(options);
        this.tableColumn = [{ title: "抗生素", field: "medname" }];
        this.columnData.forEach((item) => {
          item.content.forEach((ele) => {
            this.tableColumn.push({ title: ele.field, field: ele.field });
          });
        });
        let filtertxt = this.getExportFilter();
        this.$pub.exportTableExcel(this.rightTableData, this.tableColumn, "LIS943 常见10种细菌耐药统计表detail.xlsx", filtertxt, "统计条件：");
      }
      this.dialogExport = false;
    },
    // 获取当前导出文件的所有查询条件
    getExportFilter() {
      let filtertxt = "日期:" + XEUtils.toDateString(this.searchobj.strdate, "yyyy-MM-dd") + "至" + XEUtils.toDateString(this.searchobj.enddate, "yyyy-MM-dd") + "; ";
      if (this.searchobj.sample) filtertxt += "标本类型:" + this.getOptionName(this.specimenOption.filter((item) => ("," + this.searchobj.sample + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.reqdept) filtertxt += "科室:" + this.getOptionName(this.deptOption.filter((item) => ("," + this.searchobj.reqdept + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.patsex) filtertxt += "性别:" + this.getOptionName(this.sexOption.filter((item) => this.searchobj.patsex == item.value)) + "; ";
      if (this.searchobj.bypat) filtertxt += "按病人统计; ";
      if (this.searchobj.rescode) filtertxt += "耐药机制:" + this.getOptionName(this.resdictOption.filter((item) => this.searchobj.rescode == item.data)) + "; ";
      if (this.searchobj.rptunitid) filtertxt += "报告单元:" + this.getOptionName(this.rptunitOption.filter((item) => ("," + this.searchobj.rptunitid + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.pattype) filtertxt += "病人类型:" + this.getOptionName(this.pattypeOption.filter((item) => this.searchobj.pattype == item.data)) + "; ";
      if (this.searchobj.reqward) filtertxt += "病区:" + this.getOptionName(this.wardOption.filter((item) => ("," + this.searchobj.reqward + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.germcomb) filtertxt += "细菌组:" + this.getOptionName(this.germcombOption.filter((item) => ("," + this.searchobj.germcomb + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.hospitalcode) filtertxt += "送检医院:" + this.hospitalname + "; ";
      return filtertxt;
    },
    getOptionName(option) {
      if (option && option.length > 0) {
        let optionname = "";
        option.forEach((item) => {
          if (item.hasOwnProperty("display")) {
            optionname += item.display + ",";
          } else {
            optionname += item.label + ",";
          }
        });
        return optionname.substring(0, optionname.length - 1);
      } else {
        return "";
      }
    },
    BtnPrint() { },
    InitPage() {
      this.leftloading = true;
      this.rightloading = true;
      this.$tool
        .request({
          url: "LIS/LIS9/LIS943",
          method: "post",
          data: {
            action: "InitPage",
            ...this.searchobj,
          },
        })
        .then((response) => {
          if (response.errcode == "1") {
            response.Data.forEach((item, index) => {
              if (index < 10) {
                item.chkflag = "1";
                item.chkcnt = ++index;
              } else {
                item.chkflag = "0";
              }
            });
            this.leftTableData = response.Data;
            this.handRightData(response);
          } else {
            this.$alert(response.errmsg, "提示");
            this.leftTableData = [];
            this.rightTableData = [];
          }

          this.rightloading = false;
          this.leftloading = false;
        })
        .catch((e) => {
          this.$alert(e, "出错");
          this.rightloading = false;
          this.leftloading = false;
        });
    },
    handRightData(response) {
      ++this.xTablekey;
      this.columnData = response.RData.Cols;
      response.RData.MedData.forEach((item) => {
        var keyArr = Object.keys(item);
        keyArr.forEach((titlekey) => {
          if (titlekey.includes("_R") || titlekey.includes("_I") || titlekey.includes("_S")) {
            if (titlekey.includes("AVG")) {
              if (!!item[titlekey]) {
                item[titlekey] = item[titlekey].toFixed(1) + "%";
              }
            }
            else {
              if (!titlekey.includes("Num")) {
                if (!!item[titlekey]) {
                  var title = titlekey + "Num";
                  item[titlekey] = item[title] + " (" + item[titlekey].toFixed(1) + "%)";
                }
              }
            }
          }
        });
      });
      this.rightTableData = response.RData.MedData;
    },
    rCellDblClick({ row, column }) {
      let itemcode = "";
      let ishas = false;
      this.columnData.forEach((item) => {
        item.content.forEach((ele) => {
          if (!ishas && ele.field == column.property) {
            itemcode = ele.code;
            ishas = true;
          }
        })
      })
      this.selrow = row;
      if (column.property.includes("_R") || column.property.includes("_I") || column.property.includes("_S")) {
        if (!column.property.includes("AVG") && !column.property.includes("Num")) {
          if (!!row[column.property]) {
            this.$tool
              .request({
                url: "LIS/LIS9/LIS943",
                method: "post",
                data: {
                  action: "getDetail",
                  medcode: row.medcode,
                  medname: row.medname,
                  dbcliccol: column.property,
                  itemcode: itemcode,
                  ...this.searchobj,
                },
              })
              .then((response) => {
                if (response.errcode == "1") {
                  this.patdetailtabledata = response.RData;
                  this.antibiotic = row.medname;
                  this.bacteria = column.property.split('_')[0];
                  this.reaction = column.property.split('_')[1];
                  this.dialogDetailVisible = true;
                } else {
                  this.$alert(response.errmsg, "提示");
                }
              })
              .catch((e) => {
                this.$alert(e, "出错");
              });
          }
        }
      }
    },
    cellClassName({ row, column }) {
      if (column.property.includes("_R") || column.property.includes("_I") || column.property.includes("_S")) {
        if (!column.property.includes("AVG") && !column.property.includes("Num")) {
          if (!!row[column.property]) {
            return "sample-tips";
          }
        }
      }
    },
    hospitalchange(code, name) {
      this.searchobj.hospitalcode = code;
      this.hospitalname = name;
    },
    formatFun({ cellValue, column, row }) {
      if (["hospcode", "hospitalcode"].includes(column.property)) {
        try {
          let hospname = this.hospOption.find((m) => m.data == cellValue);
          if (hospname != undefined && hospname != null) {
            return hospname.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (["req_deptno", "labdeptcode"].includes(column.property)) {
        try {
          let deptname = this.deptOption.find((m) => m.data == cellValue);
          if (deptname != undefined && deptname != null) {
            return deptname.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (column.property == "pat_typecode") {
        try {
          let pattypename = this.pattypeOption.find((m) => m.data == cellValue);
          if (pattypename != undefined && pattypename != null) {
            return pattypename.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (["req_docno"].includes(column.property)) {
        //申请医生
        try {
          let doctorname = this.doctorOption.find((m) => m.data == cellValue);
          if (doctorname != undefined && doctorname != null) {
            return doctorname.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (["rechk_user", "report_user"].includes(column.property)) {
        //检验医生，审核医生
        try {
          let username = this.userOption.find((m) => m.data == cellValue);
          if (username != undefined && username != null) {
            return username.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (column.property == "rptunitid") {
        try {
          let rptunitname = this.rptunitOption.find((m) => m.data == cellValue);
          if (rptunitname != undefined && rptunitname != null) {
            return rptunitname.display;
          } else {
            return cellValue;
          }
        } catch { }
      } else if (column.property == "specimen_code") {
        try {
          let specimenname = this.specimenOption.find((m) => m.data == cellValue);
          if (specimenname != undefined && specimenname != null) {
            return specimenname.display;
          } else {
            return cellValue;
          }
        } catch {
          return cellValue;
        }
      } else if (column.property == "pat_sex") {
        if (cellValue == "1") {
          return "男";
        } else if (cellValue == "2") {
          return "女";
        } else {
          return "";
        }
      } else if (column.property == "charge_flag") {
        try {
          let rptunitname = this.chargeflagOption.find((m) => m.value == cellValue);
          if (rptunitname != undefined && rptunitname != null) {
            return rptunitname.label;
          } else {
            return cellValue;
          }
        } catch { }
      } else {
        return cellValue;
      }
    },
    BtnNextOne() {
      let data = this.$refs.xTable.afterFullData;
      let fdata = data.filter((item) => item.chkflag == "1");
      let row = XEUtils.max(fdata, (item) => item.chkcnt);
      let rowindex = data.findIndex((m) => m.rpt_itemcode == row.rpt_itemcode);
      rowindex = rowindex + 1;
      let icnt = 0;
      for (let index = rowindex; index < rowindex + 10; index++) {
        data[index].chkflag = "1";
        data[index].chkcnt = ++icnt;
      }
      fdata.forEach((item) => {
        item.chkflag = "0";
        item.chkcnt = 0;
      });
      setTimeout(() => {
        this.$refs.xTable.scrollToRow(row);
      }, 10);
      this.BtnStatistics();
    },
    BtnReplaeFrequency() { },
    //统计
    async BtnStatistics() {
      try {
        let data = this.$refs.xTable.afterFullData;
        let fdata = data.filter((item) => item.chkflag == "1");
        if (fdata.length > 0) {
          this.rightloading = true;
          let rptitemnames = "";
          let rptitemcodes = "";
          fdata.forEach((item) => {
            rptitemnames += item.rpt_itemname + "(" + item.rpt_itemcode + ")" + ",";
            //rptitemnames += item.rpt_itemname + ",";
            rptitemcodes += item.rpt_itemcode + ",";
          });
          const response = await this.$tool.request({
            url: "LIS/LIS9/LIS943",
            method: "post",
            data: {
              action: "getMed",
              rptitems: rptitemnames,
              rptitemcodes: rptitemcodes,
              ...this.searchobj,
            },
          });
          this.handRightData(response);
          this.rightloading = false;
        }
      } catch (e) {
        this.rightloading = false;
        this.$message.warning(e);
      }
    },
    //左边列表勾选
    ChkflagChange(row) {
      let data = this.$refs.xTable.afterFullData;
      let fdata = {};
      if (row.chkflag == "1") {
        fdata = data.filter((item) => item.chkflag == "1");
        if (fdata.length <= 10) {
          fdata.forEach((item, index) => {
            item.chkcnt = ++index;
          });
        } else {
          this.$alert("一次最多可以选择10个细菌！", "提示");
          row.chkflag = "0";
        }
      } else {
        row.chkcnt = 0;
        fdata = data.filter((item) => item.chkcnt > 0);
        fdata.forEach((item, index) => {
          item.chkcnt = ++index;
        });
      }
    },
    formatFun({ cellValue, column, row }) {
      return this.retForamtVal(cellValue, column.property);
    },
    retForamtVal(cellValue, column) {
      if (column == "hospcode") {
        try {
          //送检医院
          let hosname = this.hospOption.find((m) => m.data == cellValue);
          if (hosname != undefined && hosname != null) {
            return hosname.display;
          } else {
            return cellValue;
          }
        } catch {
          return cellValue;
        }
      } else if (column == "specimen_code") {
        try {
          //标本类型
          let specimen_name = this.specimenOption.find((m) => m.data == cellValue);
          if (specimen_name != undefined && specimen_name != null) {
            return specimen_name.display;
          } else {
            return cellValue;
          }
        } catch {
          return cellValue;
        }
      } else if (column == "pat_typecode") {
        try {
          //来源
          let pat_typename = this.pattypeOption.find((m) => m.data == cellValue);
          if (pat_typename != undefined && pat_typename != null) {
            return pat_typename.display;
          } else {
            return cellValue;
          }
        } catch {
          return cellValue;
        }
      } else if (column == "req_deptno") {
        try {
          //申请科室
          let deptname = this.deptOption.find((m) => m.data == cellValue);
          if (deptname != undefined && deptname != null) {
            return deptname.display;
          } else {
            return cellValue;
          }
        } catch {
          return cellValue;
        }
      } else if (column == "req_wardno") {
        // 病区
        try {
          let req_wardname = this.wardOption.find((m) => m.data == cellValue);
          if (req_wardname != undefined && req_wardname != null) {
            return req_wardname.display;
          } else {
            return cellValue;
          }
        } catch {
          return cellValue;
        }
      } else {
        return cellValue;
      }
    },
  },
};
</Script>

<style scoped>
.pagetop {
  width: 100%;
  height: 95px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 100px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  left: 0px;
  right: 0px;
  overflow: auto;
}

.el-checkbox__label {
  padding: 0px;
}

.left_nav {
  width: 20%;
  height: 100%;
  border-right: 1px solid #ccc;
  padding: 0px 0px 0px 0px;
  float: left;
  display: inline;
}

.left_nav div {
  cursor: pointer;
  height: 40px;
  width: 100%;
  float: left;
  padding-left: 20px;
  line-height: 40px;
}

.left_nav .active {
  background-color: DeepSkyBlue;
}

.right_nav {
  width: 80%;
  height: 100%;
  display: inline-block;
  vertical-align: top;
  float: left;
  display: inline;
}

table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}

.table1style tr td {
  padding: 1px 2px 0px 2px;
}

::v-deep .sample-tips {
  color: blue;
  cursor: pointer;
  text-decoration: underline;
}

::v-deep .mytable-style .vxe-footer--column.col-blue {
  color: blue !important;
  font-weight: bold;
}

::v-deep .mytable-style .vxe-body--row.row-blue {
  color: blue !important;
  font-weight: bold;
}

::v-deep .el-checkbox__label {
  padding-left: 0px;
}

::v-deep.myclass .vxe-table--header .vxe-header--column {
  border-right: 1px solid #cccccc;
  border-bottom: 1px solid #ccc;
}

::v-deep .el-icon-time {
  line-height: 18px !important;
}

::v-deep .el-range__close-icon {
  line-height: 18px !important;
}

::v-deep .el-range-editor--small .el-range-separator {
  line-height: 17px !important;
}

.operation-list {
  float: right;
  margin-right: 5px;
  margin-bottom: 5px;
}

::-webkit-scrollbar {
  width: 0px;
  height: 5px;
  border: 4px solid white;
}

::-webkit-scrollbar-thumb {
  background-color: #c1c1c1;
}

::-webkit-scrollbar-track {
  background-color: #f1f1f1;
}

/* Buttons */
::-webkit-scrollbar-button:single-button {
  background-color: #bbbbbb;
  display: block;
  border-style: solid;
  height: 5px;
  width: 5px;
}

/* Left */
::-webkit-scrollbar-button:horizontal:decrement {
  margin-right: 2px;
  border-width: 4px 4px 4px 0;
  border-color: #f1f1f1 transparent #f1f1f1 #f1f1f1;
  background-color: #000000;
}

::-webkit-scrollbar-button:horizontal:decrement:hover {
  border-color: #d2d2d2 transparent #d2d2d2 #d2d2d2;
}

/* Right */
::-webkit-scrollbar-button:horizontal:increment {
  margin-left: 2px;
  border-width: 4px 0 4px 4px;
  border-color: #f1f1f1 #f1f1f1 #f1f1f1 transparent;
  background-color: #000000;
}

::-webkit-scrollbar-button:horizontal:increment:hover {
  border-color: #d2d2d2 #d2d2d2 #d2d2d2 transparent;
}
</style>
